package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.GoodsPurchaseDetail;
import com.ruoyi.service.IGoodsPurchaseDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购订单明细Controller
 * 
 * @author ruoyi
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/webshop/GoodsPurchaseDetail")
public class GoodsPurchaseDetailController extends BaseController
{
    @Autowired
    private IGoodsPurchaseDetailService goodsPurchaseDetailService;

    /**
     * 查询采购订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPurchaseDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsPurchaseDetail goodsPurchaseDetail)
    {
        startPage();
        List<GoodsPurchaseDetail> list = goodsPurchaseDetailService.selectGoodsPurchaseDetailList(goodsPurchaseDetail);
        return getDataTable(list);
    }

    /**
     * 导出采购订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPurchaseDetail:export')")
    @Log(title = "采购订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsPurchaseDetail goodsPurchaseDetail)
    {
        List<GoodsPurchaseDetail> list = goodsPurchaseDetailService.selectGoodsPurchaseDetailList(goodsPurchaseDetail);
        ExcelUtil<GoodsPurchaseDetail> util = new ExcelUtil<GoodsPurchaseDetail>(GoodsPurchaseDetail.class);
        util.exportExcel(response, list, "采购订单明细数据");
    }

    /**
     * 获取采购订单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPurchaseDetail:query')")
    @GetMapping(value = "/{purchaseDetailId}")
    public AjaxResult getInfo(@PathVariable("purchaseDetailId") Long purchaseDetailId)
    {
        return success(goodsPurchaseDetailService.selectGoodsPurchaseDetailByPurchaseDetailId(purchaseDetailId));
    }

    /**
     * 新增采购订单明细
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPurchaseDetail:add')")
    @Log(title = "采购订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsPurchaseDetail goodsPurchaseDetail)
    {
        return toAjax(goodsPurchaseDetailService.insertGoodsPurchaseDetail(goodsPurchaseDetail));
    }

    /**
     * 修改采购订单明细
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPurchaseDetail:edit')")
    @Log(title = "采购订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsPurchaseDetail goodsPurchaseDetail)
    {
        return toAjax(goodsPurchaseDetailService.updateGoodsPurchaseDetail(goodsPurchaseDetail));
    }

    /**
     * 删除采购订单明细
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPurchaseDetail:remove')")
    @Log(title = "采购订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseDetailIds}")
    public AjaxResult remove(@PathVariable Long[] purchaseDetailIds)
    {
        return toAjax(goodsPurchaseDetailService.deleteGoodsPurchaseDetailByPurchaseDetailIds(purchaseDetailIds));
    }
}
